package com.dateConstruction._01_complex;

import java.util.Objects;

public class Complex {

    private double real;
    private double imag;
    
    private Complex(double real, double imag) {
        super();
        this.real = real;
        this.imag = imag;
    }

    public double getReal() {
        return real;
    }

    public void setReal(double real) {
        this.real = real;
    }

    public double getImag() {
        return imag;
    }

    public void setImag(double imag) {
        this.imag = imag;
    }
    
    @Override
    public String toString() {
        return "(" + real + " + " + imag + "i)";
    }

    private static Complex add(Complex c1, Complex c2) {
        // TODO Auto-generated method stub
        Complex c3 = new Complex(c1.getReal() + c2.getReal(), c1.getImag() + c2.getImag());
        return c3;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(imag, real);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Complex other = (Complex) obj;
        return this.real == other.real && this.imag == other.imag;
    }

    private void add(Complex c2) {
        // TODO Auto-generated method stub
        real += c2.getReal();
        imag += c2.getImag();
    }
    
    public static void main(String[] args) {
        Complex c1 = new Complex(3, 5);
        Complex c2 = new Complex(4, 2);
        Complex c3 = add(c1, c2);
        System.out.println(c1 + " + " + c2 + " = " + c3);
        
        c1.add(c2);
        System.out.println("c1" + " = " + c1);
        System.out.println("c1 == c3?: " + (c1 == c2));
        System.out.println("c1.equals(c3)?: " + c1.equals(c3)); 
    }

}
